
package com.insigma.business.qrcode.soldier.service.impl;


import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.soldier.dao.DataScreenStatisticsDao;
import com.insigma.business.qrcode.soldier.dto.SequenceNameConstant;
import com.insigma.business.qrcode.soldier.entity.DataScreenStatisticsDO;
import com.insigma.business.qrcode.soldier.request.DataScreenStatisticsBSearcher;
import com.insigma.business.qrcode.soldier.service.DataScreenStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service("dataScreenStatisticsService")
public class DataScreenStatisticsServiceImpl implements DataScreenStatisticsService {

    @Autowired(required = false)
    private DataScreenStatisticsDao dataScreenStatisticsDao;
    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;

    @Override
    public List<DataScreenStatisticsDO> search(final DataScreenStatisticsBSearcher dataScreenStatisticsBSearcher) {
        return dataScreenStatisticsDao.search(dataScreenStatisticsBSearcher);
    }

    @Override
    public DataScreenStatisticsDO get(final String id) {
        return dataScreenStatisticsDao.get(id);
    }

    @Override
    public Integer insert(final DataScreenStatisticsDO dataScreenStatisticsDO) {
        dataScreenStatisticsDO.setId(sequenceGenerator.genKey(SequenceNameConstant.DATA_SCREEN_STATISTICS_ID));
        return dataScreenStatisticsDao.insert(dataScreenStatisticsDO);
    }

    @Override
    public Integer update(final DataScreenStatisticsDO dataScreenStatisticsDO) {
        return dataScreenStatisticsDao.update(dataScreenStatisticsDO);
    }

    @Override
    public Integer delete(final String id, final String modifierType, final String modifierId) {
        return dataScreenStatisticsDao.delete(id, modifierType, modifierId);
    }

    @Override
    public DataScreenStatisticsDO getLastByAreaCode(String adminAreaCode, String type, Integer expireTime) {
        return dataScreenStatisticsDao.getLastByAreaCodeAndTime(adminAreaCode, type, new Date(System.currentTimeMillis() - expireTime));
    }

    @Override
    public DataScreenStatisticsDO getLastByAreaCode(String adminAreaCode, String type) {
        return dataScreenStatisticsDao.getLastByAreaCodeAndTime(adminAreaCode, type, null);
    }

    @Override
    public DataScreenStatisticsDO getLastOneByAreaCode(String adminAreaCode, String type) {
        return dataScreenStatisticsDao.getLastByAreaCode(adminAreaCode, type);
    }


}
